﻿using System.Web.Http;
using Medora.Data;
using Medora.Data.Helpers;
using Medora.DataContract;
using Medora.Model.Classifiers;
using Medora.Model.Institutions;
using Medora.Services;
using Medora.Services.Classifiers;
using Medora.Services.Institutions;
using Medora.Services.Persons;
using Medora.Services.Utils;
using Ninject;

namespace MvcApp.App_Start
{
    public class IocConfig
    {
        /// <summary>
        /// Registers the Invertion of Control.
        /// </summary>
        /// <param name="config">The config.</param>
        public static void RegisterIoc(HttpConfiguration config)
        {
            var kernel = new StandardKernel(); // Ninject IoC

            // These registrations are "per instance request".
            // See http://blog.bobcravens.com/2010/03/ninject-life-cycle-management-or-scoping/


            kernel.Bind<RepositoryFactories>().To<RepositoryFactories>().InSingletonScope();
            kernel.Bind<IRepositoryProvider>().To<RepositoryProvider>();
            
            
            kernel.Bind<IUow>().To<Uow>();

            kernel.Bind<IUserService>().To<UsersService>();
            kernel.Bind<IDepartmentsService>().To<DepartmentsService>();
            kernel.Bind<IService<Speciality, SpecialityFilter>>().To<SpecialitiesService>();
            
            kernel.Bind<IService<Position, PositionFilter>>().To<PositionsService>();
            kernel.Bind<IService<ScheduleType, ClassifierFilter>>().To<ScheduleTypesService>();
            
            kernel.Bind<IProvidersService>().To<ProvidersService>();
            kernel.Bind<ISectorsService>().To<SectorsService>();
            kernel.Bind<IPersonsService>().To<PersonsService>();
            kernel.Bind<IScheduleTemplatesService>().To<ScheduleTemplatesService>();
            kernel.Bind<IScheduleTemplateItemsService>().To<ScheduleTemplateItemsService>();
            kernel.Bind<IScheduleItemsService>().To<ScheduleItemsService>();
            kernel.Bind(typeof(IFilterConstructor<,>)).To(typeof(FilterConstructor<,>));

            
            
            // Tell WebApi how to use our Ninject IoC
            config.DependencyResolver = new NinjectDependencyResolver(kernel);
        }
    }
}